import { create } from "zustand"
import { immer } from "zustand/middleware/immer"

interface Store {
  count: number
  num: number
  nested: { count: number }
  increase: () => void
  remove: () => void
  update: () => void
}

const useCountStore = create<Store>()(
  immer((set) => ({
    count: 0,
    num: 0,
    nested: { count: 0 },
    increase: () =>
      set((state) => {
        state.count++
      }),
    remove: () => set({ count: 0 }),
    update: () =>
      set((state) => {
        state.nested.count++
      })
  }))
)

export default useCountStore
